<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <title>Docker微服务构建指南 | 狼组安全团队公开知识库</title>
    <meta name="description" content="">
    <meta name="generator" content="VuePress 1.7.1">
    <link rel="icon" href="/assets/logo.svg">
    <script type="text/javascript" src="/assets/js/push.js"></script>
    <meta name="description" content="致力于打造信息安全乌托邦">
    <meta name="referrer" content="never">
    <meta name="keywords" content="知识库,公开知识库,狼组,狼组安全团队知识库,knowledge">
    <link rel="preload" href="/assets/css/0.styles.32ca519c.css" as="style"><link rel="preload" href="/assets/js/app.f7464420.js" as="script"><link rel="preload" href="/assets/js/2.26207483.js" as="script"><link rel="preload" href="/assets/js/14.d2a5440c.js" as="script"><link rel="prefetch" href="/assets/js/10.55514509.js"><link rel="prefetch" href="/assets/js/11.ec576042.js"><link rel="prefetch" href="/assets/js/12.a5584a2f.js"><link rel="prefetch" href="/assets/js/13.c9f84b2e.js"><link rel="prefetch" href="/assets/js/15.2f271296.js"><link rel="prefetch" href="/assets/js/16.0895ce42.js"><link rel="prefetch" href="/assets/js/17.627e2976.js"><link rel="prefetch" href="/assets/js/18.73745a4c.js"><link rel="prefetch" href="/assets/js/19.19350186.js"><link rel="prefetch" href="/assets/js/20.e4eac589.js"><link rel="prefetch" href="/assets/js/21.fc0657ba.js"><link rel="prefetch" href="/assets/js/22.f4a1220f.js"><link rel="prefetch" href="/assets/js/23.c8cce92d.js"><link rel="prefetch" href="/assets/js/24.46225ec2.js"><link rel="prefetch" href="/assets/js/25.9b6d75e4.js"><link rel="prefetch" href="/assets/js/26.288f535e.js"><link rel="prefetch" href="/assets/js/27.865bdc75.js"><link rel="prefetch" href="/assets/js/28.f4224fef.js"><link rel="prefetch" href="/assets/js/29.6393a40b.js"><link rel="prefetch" href="/assets/js/3.a509f503.js"><link rel="prefetch" href="/assets/js/30.d5a49f97.js"><link rel="prefetch" href="/assets/js/31.eb3647df.js"><link rel="prefetch" href="/assets/js/32.7f48a571.js"><link rel="prefetch" href="/assets/js/33.1f374ffa.js"><link rel="prefetch" href="/assets/js/34.5a911179.js"><link rel="prefetch" href="/assets/js/35.d2bcc7ef.js"><link rel="prefetch" href="/assets/js/36.42e440bd.js"><link rel="prefetch" href="/assets/js/37.dedbbdea.js"><link rel="prefetch" href="/assets/js/38.d68d1f69.js"><link rel="prefetch" href="/assets/js/39.e278f860.js"><link rel="prefetch" href="/assets/js/4.35636da8.js"><link rel="prefetch" href="/assets/js/40.97f4e937.js"><link rel="prefetch" href="/assets/js/41.38630688.js"><link rel="prefetch" href="/assets/js/42.cae56aa5.js"><link rel="prefetch" href="/assets/js/43.61a04b16.js"><link rel="prefetch" href="/assets/js/44.5c6230f2.js"><link rel="prefetch" href="/assets/js/45.0f1355ae.js"><link rel="prefetch" href="/assets/js/46.c1906649.js"><link rel="prefetch" href="/assets/js/47.7ae220ce.js"><link rel="prefetch" href="/assets/js/48.59af224e.js"><link rel="prefetch" href="/assets/js/49.6a33a171.js"><link rel="prefetch" href="/assets/js/5.08ab40ee.js"><link rel="prefetch" href="/assets/js/50.f14601d2.js"><link rel="prefetch" href="/assets/js/51.f20841fd.js"><link rel="prefetch" href="/assets/js/52.fb0a5327.js"><link rel="prefetch" href="/assets/js/53.8013048c.js"><link rel="prefetch" href="/assets/js/54.d132c2f8.js"><link rel="prefetch" href="/assets/js/55.87aa8b5d.js"><link rel="prefetch" href="/assets/js/56.161f38ad.js"><link rel="prefetch" href="/assets/js/57.bd6a2ef2.js"><link rel="prefetch" href="/assets/js/58.8a69f15a.js"><link rel="prefetch" href="/assets/js/59.93c0e2de.js"><link rel="prefetch" href="/assets/js/6.fda5ce3a.js"><link rel="prefetch" href="/assets/js/60.10091d44.js"><link rel="prefetch" href="/assets/js/61.cd1e3b10.js"><link rel="prefetch" href="/assets/js/62.9c0ad8c5.js"><link rel="prefetch" href="/assets/js/63.4a8dd9d2.js"><link rel="prefetch" href="/assets/js/64.6bf3fede.js"><link rel="prefetch" href="/assets/js/65.7a2ccc50.js"><link rel="prefetch" href="/assets/js/66.874d563b.js"><link rel="prefetch" href="/assets/js/67.bb86eab2.js"><link rel="prefetch" href="/assets/js/68.c1db2a2b.js"><link rel="prefetch" href="/assets/js/69.8141480b.js"><link rel="prefetch" href="/assets/js/7.d1fe6bef.js"><link rel="prefetch" href="/assets/js/70.9fb74c80.js"><link rel="prefetch" href="/assets/js/71.d1e4e9ab.js"><link rel="prefetch" href="/assets/js/72.e6bf83fb.js"><link rel="prefetch" href="/assets/js/73.6dd6c980.js"><link rel="prefetch" href="/assets/js/74.3612ba47.js"><link rel="prefetch" href="/assets/js/75.6e1a2434.js"><link rel="prefetch" href="/assets/js/76.5bfa4bcc.js"><link rel="prefetch" href="/assets/js/77.784df031.js"><link rel="prefetch" href="/assets/js/78.aa94a0a0.js"><link rel="prefetch" href="/assets/js/79.c4e9a4f2.js"><link rel="prefetch" href="/assets/js/8.63fd05d7.js"><link rel="prefetch" href="/assets/js/80.8d47d1f7.js"><link rel="prefetch" href="/assets/js/81.1160b022.js"><link rel="prefetch" href="/assets/js/82.7d17e5c8.js"><link rel="prefetch" href="/assets/js/83.a2ff144a.js"><link rel="prefetch" href="/assets/js/84.53d29383.js"><link rel="prefetch" href="/assets/js/9.b49161a4.js">
    <link rel="stylesheet" href="/assets/css/0.styles.32ca519c.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container"><header class="navbar"><div class="ant-row"><div class="nav-button"><i aria-label="icon: bars" class="anticon anticon-bars"><svg viewBox="0 0 1024 1024" focusable="false" data-icon="bars" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M912 192H328c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h584c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8zm0 284H328c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h584c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8zm0 284H328c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h584c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8zM104 228a56 56 0 1 0 112 0 56 56 0 1 0-112 0zm0 284a56 56 0 1 0 112 0 56 56 0 1 0-112 0zm0 284a56 56 0 1 0 112 0 56 56 0 1 0-112 0z"></path></svg></i> <span></span></div> <div class="ant-col ant-col-xs-24 ant-col-sm-24 ant-col-md-6 ant-col-lg-5 ant-col-xl-5 ant-col-xxl-4"><a href="/" class="router-link-active home-link"><img src="/assets/logo.svg" alt="狼组安全团队公开知识库" class="logo"> <span class="site-name">狼组安全团队公开知识库</span></a> <div class="search-box mobile-search"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div></div> <div class="ant-col ant-col-xs-0 ant-col-sm-0 ant-col-md-18 ant-col-lg-19 ant-col-xl-19 ant-col-xxl-20"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><ul role="menu" id="nav" class="ant-menu ant-menu-horizontal ant-menu-root ant-menu-light"><li role="menuitem" class="ant-menu-submenu ant-menu-submenu-horizontal ant-menu-overflowed-submenu" style="display:none;"><div aria-haspopup="true" class="ant-menu-submenu-title"><span>···</span><i class="ant-menu-submenu-arrow"></i></div></li><li role="menuitem" class="ant-menu-item"><a href="/" class="router-link-active">
          首页
        </a></li><li role="menuitem" class="ant-menu-submenu ant-menu-submenu-horizontal ant-menu-overflowed-submenu" style="display:none;"><div aria-haspopup="true" class="ant-menu-submenu-title"><span>···</span><i class="ant-menu-submenu-arrow"></i></div></li><li role="menuitem" class="ant-menu-item"><a href="/guide/">
          使用指南
        </a></li><li role="menuitem" class="ant-menu-submenu ant-menu-submenu-horizontal ant-menu-overflowed-submenu" style="display:none;"><div aria-haspopup="true" class="ant-menu-submenu-title"><span>···</span><i class="ant-menu-submenu-arrow"></i></div></li><li role="menuitem" class="ant-menu-item"><a href="/knowledge/" class="router-link-active">
          知识库
        </a></li><li role="menuitem" class="ant-menu-submenu ant-menu-submenu-horizontal ant-menu-overflowed-submenu" style="display:none;"><div aria-haspopup="true" class="ant-menu-submenu-title"><span>···</span><i class="ant-menu-submenu-arrow"></i></div></li><li role="menuitem" class="ant-menu-item"><a href="/opensource/">
          开源项目
        </a></li><li role="menuitem" class="ant-menu-submenu ant-menu-submenu-horizontal ant-menu-overflowed-submenu" style="visibility:hidden;position:absolute;"><div aria-haspopup="true" class="ant-menu-submenu-title"><span>···</span><i class="ant-menu-submenu-arrow"></i></div></li></ul> <a href="https://github.com/wgpsec" target="_blank" rel="noopener noreferrer" class="repo-link"><i aria-label="icon: github" class="anticon anticon-github"><svg viewBox="64 64 896 896" focusable="false" data-icon="github" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M511.6 76.3C264.3 76.2 64 276.4 64 523.5 64 718.9 189.3 885 363.8 946c23.5 5.9 19.9-10.8 19.9-22.2v-77.5c-135.7 15.9-141.2-73.9-150.3-88.9C215 726 171.5 718 184.5 703c30.9-15.9 62.4 4 98.9 57.9 26.4 39.1 77.9 32.5 104 26 5.7-23.5 17.9-44.5 34.7-60.8-140.6-25.2-199.2-111-199.2-213 0-49.5 16.3-95 48.3-131.7-20.4-60.5 1.9-112.3 4.9-120 58.1-5.2 118.5 41.6 123.2 45.3 33-8.9 70.7-13.6 112.9-13.6 42.4 0 80.2 4.9 113.5 13.9 11.3-8.6 67.3-48.8 121.3-43.9 2.9 7.7 24.7 58.3 5.5 118 32.4 36.8 48.9 82.7 48.9 132.3 0 102.2-59 188.1-200 212.9a127.5 127.5 0 0 1 38.1 91v112.5c.8 9 0 17.9 15 17.9 177.1-59.7 304.6-227 304.6-424.1 0-247.2-200.4-447.3-447.5-447.3z"></path></svg></i></a></nav></div></div> <!----></header> <aside class="sidebar"><div><div class="promo"><div id="promo_3"><div class="promo_title">赞助商</div> <button type="button" class="ant-btn ant-btn-primary ant-btn-background-ghost"><span>成为赞助商</span></button></div></div> <div role="separator" id="reset-margin" class="ant-divider ant-divider-horizontal ant-divider-dashed"></div></div> <ul class="sidebar-links"><li><a href="/knowledge/" aria-current="page" title="知识库广告位招租" class="sidebar-link">知识库广告位招租</a></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>CTF</span> <span class="arrow right"><i aria-label="icon: down" class="anticon anticon-down"><svg viewBox="64 64 896 896" focusable="false" data-icon="down" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M884 256h-75c-5.1 0-9.9 2.5-12.9 6.6L512 654.2 227.9 262.6c-3-4.1-7.8-6.6-12.9-6.6h-75c-6.5 0-10.3 7.4-6.5 12.7l352.6 486.1c12.8 17.6 39 17.6 51.7 0l352.6-486.1c3.9-5.3.1-12.7-6.4-12.7z"></path></svg></i></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading open"><span>基础知识</span> <span class="arrow down"><i aria-label="icon: down" class="anticon anticon-down"><svg viewBox="64 64 896 896" focusable="false" data-icon="down" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M884 256h-75c-5.1 0-9.9 2.5-12.9 6.6L512 654.2 227.9 262.6c-3-4.1-7.8-6.6-12.9-6.6h-75c-6.5 0-10.3 7.4-6.5 12.7l352.6 486.1c12.8 17.6 39 17.6 51.7 0l352.6-486.1c3.9-5.3.1-12.7-6.4-12.7z"></path></svg></i></span></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/knowledge/base/" aria-current="page" title="分类简介" class="sidebar-link">分类简介</a></li><li><a href="/knowledge/base/safety.html" title="网络安全设备常识" class="sidebar-link">网络安全设备常识</a></li><li><a href="/knowledge/base/network-web.html" title="【网络基础】Web应用常识" class="sidebar-link">【网络基础】Web应用常识</a></li><li><a href="/knowledge/base/network-tcp-ip.html" title="【网络基础】TCP/IP协议" class="sidebar-link">【网络基础】TCP/IP协议</a></li><li><a href="/knowledge/base/network-http.html" title="【网络基础】HTTP协议" class="sidebar-link">【网络基础】HTTP协议</a></li><li><a href="/knowledge/base/network-https.html" title="【网络基础】SSL双向认证" class="sidebar-link">【网络基础】SSL双向认证</a></li><li><a href="/knowledge/base/network-route.html" title="【网络基础】路由协议" class="sidebar-link">【网络基础】路由协议</a></li><li><a href="/knowledge/base/linux-cmd.html" title="【操作系统】Linux基础命令" class="sidebar-link">【操作系统】Linux基础命令</a></li><li><a href="/knowledge/base/linux-awk.html" title="【操作系统】Linux三剑客" class="sidebar-link">【操作系统】Linux三剑客</a></li><li><a href="/knowledge/base/git-base.html" title="Git基本用法" class="sidebar-link">Git基本用法</a></li><li><a href="/knowledge/base/docker-base.html" aria-current="page" title="Docker微服务构建指南" class="active sidebar-link">Docker微服务构建指南</a></li></ul></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>工具手册</span> <span class="arrow right"><i aria-label="icon: down" class="anticon anticon-down"><svg viewBox="64 64 896 896" focusable="false" data-icon="down" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M884 256h-75c-5.1 0-9.9 2.5-12.9 6.6L512 654.2 227.9 262.6c-3-4.1-7.8-6.6-12.9-6.6h-75c-6.5 0-10.3 7.4-6.5 12.7l352.6 486.1c12.8 17.6 39 17.6 51.7 0l352.6-486.1c3.9-5.3.1-12.7-6.4-12.7z"></path></svg></i></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>Web安全</span> <span class="arrow right"><i aria-label="icon: down" class="anticon anticon-down"><svg viewBox="64 64 896 896" focusable="false" data-icon="down" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M884 256h-75c-5.1 0-9.9 2.5-12.9 6.6L512 654.2 227.9 262.6c-3-4.1-7.8-6.6-12.9-6.6h-75c-6.5 0-10.3 7.4-6.5 12.7l352.6 486.1c12.8 17.6 39 17.6 51.7 0l352.6-486.1c3.9-5.3.1-12.7-6.4-12.7z"></path></svg></i></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>攻防对抗</span> <span class="arrow right"><i aria-label="icon: down" class="anticon anticon-down"><svg viewBox="64 64 896 896" focusable="false" data-icon="down" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M884 256h-75c-5.1 0-9.9 2.5-12.9 6.6L512 654.2 227.9 262.6c-3-4.1-7.8-6.6-12.9-6.6h-75c-6.5 0-10.3 7.4-6.5 12.7l352.6 486.1c12.8 17.6 39 17.6 51.7 0l352.6-486.1c3.9-5.3.1-12.7-6.4-12.7z"></path></svg></i></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>代码审计</span> <span class="arrow right"><i aria-label="icon: down" class="anticon anticon-down"><svg viewBox="64 64 896 896" focusable="false" data-icon="down" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M884 256h-75c-5.1 0-9.9 2.5-12.9 6.6L512 654.2 227.9 262.6c-3-4.1-7.8-6.6-12.9-6.6h-75c-6.5 0-10.3 7.4-6.5 12.7l352.6 486.1c12.8 17.6 39 17.6 51.7 0l352.6-486.1c3.9-5.3.1-12.7-6.4-12.7z"></path></svg></i></span></p> <!----></section></li></ul></aside> <main class="page"> <div class="theme-antdocs-content content__default"><h1 id="docker微服务构建指南">Docker微服务构建指南 <a href="#docker微服务构建指南" class="header-anchor">#</a></h1> <blockquote><p>Docker可以轻松的为任何应用创建一个轻量级的、可移植的、自给自足的容器。</p> <p>通常用于Web应用的自动化打包和发布。</p></blockquote> <p><strong>Docker与虚拟机的区别</strong></p> <blockquote><p>与虚拟机相比，它以一种轻量级的方式实现了运行空间的隔离。</p> <p>如果物理机是一幢住宅楼，虚拟机就是大楼中的一户户套房，而容器技术就是套房里的一个个隔断。</p></blockquote> <h1 id="安装docker">安装Docker <a href="#安装docker" class="header-anchor">#</a></h1> <p>以<code>Centos</code>为例</p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>yum <span class="token function">install</span> -y yum-utils	<span class="token comment"># yum-config-manager需要用这个包</span>
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo   <span class="token comment">#安装docker官方源</span>
yum makecache
yum -y <span class="token function">install</span> docker-ce
systemctl start docker
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><p><strong>镜像下载加速，使用国内源</strong></p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code><span class="token comment">#这个用的是中科大的源，最好还是用阿里的源更稳定</span>
<span class="token function">sudo</span> <span class="token function">vim</span> /etc/docker/daemon.json
<span class="token punctuation">{</span><span class="token string">&quot;registry-mirrors&quot;</span><span class="token builtin class-name">:</span> <span class="token punctuation">[</span><span class="token string">&quot;https://docker.mirrors.ustc.edu.cn&quot;</span><span class="token punctuation">]</span><span class="token punctuation">}</span>
systemctl restart docker
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div><p>阿里云的镜像最快，但是要登陆阿里云才能用 (淘宝账号我不信你没有)</p> <p>(<a href="https://cr.console.aliyun.com/cn-beijing/instances/namespaces" target="_blank" rel="noopener noreferrer">阿里云Docker仓库地址<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a>，<a href="https://help.aliyun.com/document_detail/60743.html?spm=a2c4g.11186623.6.550.4b6c378bVmbEfb" target="_blank" rel="noopener noreferrer">使用帮助<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a>)</p> <h1 id="docker镜像命令">Docker镜像命令 <a href="#docker镜像命令" class="header-anchor">#</a></h1> <blockquote><p>Docker 镜像是一个特殊的文件系统，除了提供容器运行时所需的程序、库、资源、配置等文件外</p> <p>还包含了一些为运行时准备的一些配置参数（如匿名卷、环境变量、用户等）</p> <p>镜像不包含任何动态数据，其内容在构建之后也不会被改变</p></blockquote> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>docker search ubuntu	<span class="token comment">#查找镜像</span>
docker pull ubuntu		<span class="token comment">#拉取镜像(就是下载)</span>
docker images			<span class="token comment">#查看所有Docker镜像</span>
docker <span class="token function">history</span>			<span class="token comment">#查看镜像历史（有哪些层）</span>
docker system <span class="token function">df</span>		<span class="token comment">#查看镜像、容器、数据卷所占用的空间</span>
docker rmi -f <span class="token function">id</span>		<span class="token comment">#删除镜像</span>
docker rmi -f <span class="token variable"><span class="token variable">`</span>docker images -q<span class="token variable">`</span></span>	<span class="token comment">#删除全部镜像</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br></div></div><h1 id="docker容器命令">Docker容器命令 <a href="#docker容器命令" class="header-anchor">#</a></h1> <blockquote><p>镜像（<code>Image</code>）和容器（<code>Container</code>）的关系，就像是面向对象程序设计中的 <code>类</code> 和 <code>实例</code> 一样</p> <p>镜像是静态的定义，容器是镜像运行时的实体，容器可以被创建、启动、停止、删除、暂停等</p> <p>容器的实质是进程，但与直接在宿主执行的进程不同，容器进程运行于属于自己的独立的 [命名空间]</p> <p>因此容器可以拥有自己的 <code>root</code> 文件系统、自己的网络配置、自己的进程空间，甚至自己的用户 ID 空间</p> <p>容器内的进程是运行在一个隔离的环境里，使用起来，就好像是在一个独立于宿主的系统下操作一样</p></blockquote> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>docker <span class="token function">ps</span>			<span class="token comment">#查看所有启动的容器（若查看所有的容器包括已经关闭,添加-a参数即可）</span>
docker inspect ID	<span class="token comment">#查看容器信息（数据卷等 -&gt; &quot;Mounts&quot;）</span>
docker stats ID		<span class="token comment">#查看Docker状态</span>
docker logs ID		<span class="token comment">#查看容器日志（报错和命令）</span>

docker run -it -d --name ubuntu_wintrysec -p <span class="token number">8088</span>:80 ubuntu	
<span class="token comment">#运行Docker镜像</span>
<span class="token comment">#-d	守护态运行，不直接把执行命令的结果输出在当前宿主机下</span>
<span class="token comment">#--name参数为自定义容器名</span>
<span class="token comment">#-p参数为指定端口映射、后者为容器的端口(我们访问Docker的宿主机8080端口)</span>
<span class="token comment">#成功后台运行后会返回一个容器的id，只需要记住前两位即可</span>

docker <span class="token builtin class-name">exec</span> -it ID <span class="token function">bash</span>	
<span class="token comment">#进入一个正在运行的容器的shell，容器id前4位就行,或者容器名也行</span>

<span class="token builtin class-name">exit</span>				<span class="token comment">#退出容器</span>
docker stop ID		<span class="token comment">#停止容器运行，写容器名也行，start是开启</span>
docker <span class="token function">rm</span> ID		<span class="token comment">#删除容器</span>
docker <span class="token function">rm</span> <span class="token variable"><span class="token variable">`</span>docker <span class="token function">ps</span> -a -q<span class="token variable">`</span></span>		<span class="token comment">#删除所有已经关闭的容器，-f能把正在运行的也关闭</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br></div></div><h1 id="dockerfile定制镜像">Dockerfile定制镜像 <a href="#dockerfile定制镜像" class="header-anchor">#</a></h1> <blockquote><p><code>Dockerfile</code>用来创建一个自定义的镜像,包含了用户指定的软件依赖等，用于从无到有的构建镜像</p> <p>把每一层修改、安装、构建、操作的命令都写入一个脚本，用这个脚本来构建、定制镜像</p> <p>可以解决镜像无法重复的问题、镜像构建透明性的问题、体积的问题。</p></blockquote> <h3 id="from指定基础镜像">FROM指定基础镜像 <a href="#from指定基础镜像" class="header-anchor">#</a></h3> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>FROM ubuntu		<span class="token comment">#指定基础镜像</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>除了选择现有镜像为基础镜像外，Docker 还存在一个特殊的镜像，名为 <code>scratch</code>；</p> <p>这个镜像是虚拟的概念，并不实际存在，它表示一个空白的镜像；</p> <p>如果以 <code>scratch</code> 为基础镜像的话，意味着你不以任何镜像为基础，接下来所写的指令将作为镜像第一层开始存在；</p> <p>对于 Linux 下静态编译的程序来说，并不需要有操作系统提供运行时支持，所需的一切库都已经在可执行文件里了；</p> <p>因此直接 <code>FROM scratch</code> 会让镜像体积更加小巧，使用 Go 语言开发的应用很多会使用这种方式来制作镜像。</p> <h3 id="run执行命令">RUN执行命令 <a href="#run执行命令" class="header-anchor">#</a></h3> <p>Dockerfile 每一个 <code>RUN</code> 的行为，都会新建立一层构成新的镜像，这样会使镜像非常臃肿。</p> <p><strong>正确的写法应该这样：</strong></p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>RUN <span class="token assign-left variable">buildDeps</span><span class="token operator">=</span><span class="token string">'gcc libc6-dev make wget'</span> <span class="token punctuation">\</span>
    <span class="token operator">&amp;&amp;</span> <span class="token function">apt-get</span> update <span class="token punctuation">\</span>
    <span class="token operator">&amp;&amp;</span> <span class="token function">apt-get</span> <span class="token function">install</span> -y <span class="token variable">$buildDeps</span> <span class="token punctuation">\</span>
    <span class="token operator">&amp;&amp;</span> <span class="token function">wget</span> -O redis.tar.gz <span class="token string">&quot;http://download.redis.io/releases/redis-5.0.3.tar.gz&quot;</span> <span class="token punctuation">\</span>
    <span class="token operator">&amp;&amp;</span> <span class="token function">mkdir</span> -p /usr/src/redis <span class="token punctuation">\</span>
    <span class="token operator">&amp;&amp;</span> <span class="token function">tar</span> -xzf redis.tar.gz -C /usr/src/redis --strip-components<span class="token operator">=</span><span class="token number">1</span> <span class="token punctuation">\</span>
    <span class="token operator">&amp;&amp;</span> <span class="token function">make</span> -C /usr/src/redis <span class="token punctuation">\</span>
    <span class="token operator">&amp;&amp;</span> <span class="token function">make</span> -C /usr/src/redis <span class="token function">install</span> <span class="token punctuation">\</span>
    <span class="token operator">&amp;&amp;</span> <span class="token function">rm</span> -rf /var/lib/apt/lists/* <span class="token punctuation">\</span>
    <span class="token operator">&amp;&amp;</span> <span class="token function">rm</span> redis.tar.gz <span class="token punctuation">\</span>
    <span class="token operator">&amp;&amp;</span> <span class="token function">rm</span> -r /usr/src/redis <span class="token punctuation">\</span>
    <span class="token operator">&amp;&amp;</span> <span class="token function">apt-get</span> purge -y --auto-remove <span class="token variable">$buildDeps</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br></div></div><p>首先这些命令只有一个目的，就是编译、安装 redis 可执行文件；因此没有必要建立很多层，这是一层能解决的事情</p> <p>使用 <code>&amp;&amp;</code> 将各个所需命令串联起来，Dockerfile支持行尾添加 <code>\</code> 的命令换行方式，以及行首 <code>#</code> 进行注释的格式</p> <p>最后添加了清理工作的命令，删除了为了编译构建所需要的软件，清理了所有下载、展开的文件，并且还清理了 <code>apt</code> 缓存文件</p> <p>这是很重要的一步，镜像是多层存储，每一层的东西并不会在下一层被删除，会一直跟随着镜像</p> <p>因此镜像构建时，一定要确保每一层只添加真正需要添加的东西，任何无关的东西都应该清理掉</p> <h3 id="构建镜像">构建镜像 <a href="#构建镜像" class="header-anchor">#</a></h3> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>docker build -t ubuntu:v1 <span class="token builtin class-name">.</span>
docker build <span class="token punctuation">[</span>选项<span class="token punctuation">]</span> <span class="token operator">&lt;</span>上下文路径/URL/-<span class="token operator">&gt;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><h3 id="指令详解">指令详解 <a href="#指令详解" class="header-anchor">#</a></h3> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>COPY package.json /usr/src/
<span class="token comment">#从构建上下文目录中复制文件到新的一层的镜像内的 &lt;目标路径&gt; 位置</span>

CMD	<span class="token punctuation">[</span><span class="token string">&quot;nginx&quot;</span>, <span class="token string">&quot;-g&quot;</span>, <span class="token string">&quot;daemon off;&quot;</span><span class="token punctuation">]</span>	
<span class="token comment">#容器启动命令</span>
<span class="token comment">#直接执行 nginx 可执行文件，并且要求以前台形式运行，不能用service nginx start</span>

ENV <span class="token assign-left variable">VERSION</span><span class="token operator">=</span><span class="token number">1.0</span> <span class="token assign-left variable">NAME</span><span class="token operator">=</span><span class="token string">&quot;Vuln Range&quot;</span>
<span class="token comment">#ENV用来定义环境变量，用双引号把包含空格的引起来</span>

VOLUME /data
<span class="token comment">#匿名卷，运行时如果用户忘记了指定数据卷挂载位置，会自动挂载数据到/data目录</span>

<span class="token environment constant">USER</span> redis
<span class="token comment">#切换到指定用户，接下来会以这个用户权限执行RUN、CMD等命令</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br></div></div><p>如果以 <code>root</code> 执行的脚本，在执行期间希望改变身份，比如希望以某个已经建立好的用户来运行某个服务进程</p> <p>不要使用 <code>su</code> 或者 <code>sudo</code>，这些都需要比较麻烦的配置，而且在 TTY 缺失的环境下经常出错，建议使用 <code>gosu</code>。</p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code><span class="token comment"># 建立 redis 用户，并使用 gosu 换另一个用户执行命令</span>
RUN <span class="token function">groupadd</span> -r redis <span class="token operator">&amp;&amp;</span> <span class="token function">useradd</span> -r -g redis redis

<span class="token comment"># 下载 gosu</span>
RUN <span class="token function">wget</span> -O /usr/local/bin/gosu <span class="token string">&quot;https://github.com/tianon/gosu/releases/download/1.12/gosu-amd64&quot;</span> <span class="token punctuation">\</span>
    <span class="token operator">&amp;&amp;</span> <span class="token function">chmod</span> +x /usr/local/bin/gosu <span class="token punctuation">\</span>
    <span class="token operator">&amp;&amp;</span> gosu nobody <span class="token boolean">true</span>
    
<span class="token comment"># 设置 CMD，并以另外的用户执行</span>
CMD <span class="token punctuation">[</span> <span class="token string">&quot;exec&quot;</span>, <span class="token string">&quot;gosu&quot;</span>, <span class="token string">&quot;redis&quot;</span>, <span class="token string">&quot;redis-server&quot;</span> <span class="token punctuation">]</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br></div></div><h1 id="数据管理">数据管理 <a href="#数据管理" class="header-anchor">#</a></h1> <p>数据卷是被设计用来持久化数据的，它的生命周期独立于容器，不会在容器被删除后自动删除</p> <blockquote><p><code>数据卷</code> 可以在容器之间共享和重用</p> <p>对 <code>数据卷</code> 的修改会立马生效</p> <p>对 <code>数据卷</code> 的更新，不会影响镜像</p> <p><code>数据卷</code> 默认会一直存在，即使容器被删除</p></blockquote> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code><span class="token comment">#创建数据卷</span>
docker volume create my-vol

<span class="token comment">#查看所有数据卷</span>
docker volume <span class="token function">ls</span>

<span class="token comment">#挂载主机目录到Docker容器中</span>
--mount <span class="token assign-left variable">type</span><span class="token operator">=</span>bind,source<span class="token operator">=</span>/src/webapp,target<span class="token operator">=</span>/usr/share/nginx/html

<span class="token comment">#查看指定 数据卷 的信息</span>
docker volume inspect my-vol

<span class="token comment">#清除无主数据卷</span>
docker volume prune
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br></div></div><h1 id="网络管理">网络管理 <a href="#网络管理" class="header-anchor">#</a></h1> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>docker network <span class="token function">ls</span>		<span class="token comment">#列出已有docker网络</span>
docker network prune -f	<span class="token comment">#删除所有未使用的网络（即对应容器已经删除的网络）</span>
docker network inspect bridge	<span class="token comment">#显示一个或多个网络的详细信息</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><p><strong>外部访问容器</strong></p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code><span class="token comment">#映射指到定地址的任意端口 (随机分配一个外部访问用的端口)</span>
docker run -d -p <span class="token number">127.0</span>.0.1::80 nginx

<span class="token comment">#查看端口映射配置</span>
docker port ID
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><p><strong>容器互联</strong></p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code><span class="token comment">#1、创建一个Docker网络</span>
docker network create -d bridge my-net

<span class="token comment">#2、运行一个容器并连接到新建的 my-net 网络</span>
docker run -it --rm --name busybox1 --network my-net busybox <span class="token function">sh</span>

<span class="token comment">#3、打开新的终端，再运行一个容器并加入到 my-net 网络</span>
docker run -it --rm --name busybox2 --network my-net busybox <span class="token function">sh</span>

<span class="token comment">#4、证明容器互通，用其中一个容器，ping另外一个容器</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br></div></div><p><strong>容器访问控制</strong></p> <p>容器要想访问外部网络，需要本地系统的转发支持</p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>sysctl -w net.ipv4.ip_forward<span class="token operator">=</span><span class="token number">1</span>		<span class="token comment">#开启转发</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h1 id="docker-compose-启动服务">Docker compose(启动服务) <a href="#docker-compose-启动服务" class="header-anchor">#</a></h1> <p><code>docker compose</code> 是一个整合发布应用的利器(<a href="https://docs.docker.com/compose/install/" target="_blank" rel="noopener noreferrer">官方安装手册<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a>)</p> <p>多个容器相互配合来完成某项任务，比如<strong>Web服务容器+数据库容器</strong></p> <blockquote><ul><li>服务 (<code>service</code>)：一个应用容器，实际上可以运行多个相同镜像的实例。</li> <li>项目 (<code>project</code>)：由一组关联的应用容器组成的一个完整业务单元。</li></ul></blockquote> <p>可见，一个项目可以由多个服务（容器）关联而成，<code>Compose</code> 面向项目进行管理。</p> <p>默认的模板文件是 <code>docker-compose.yml</code></p> <hr> <p>其中定义的每个服务都必须通过 image 指令指定镜像或 build 指令（需要 <code>Dockerfile</code>，除非有registry）来自动构建</p> <p>不想部署<code>私有registry</code>又不想让<code>Dockerfile</code>存在的话，可以使用官方的<code>Docker Hub</code>, 然后使用国内源加速访问。</p> <p><strong><code>Centos</code> 安装docker-compose</strong></p> <p>首先确认已经安装好了python和pip</p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>pip <span class="token function">install</span> docker-compose -i https://pypi.mirrors.ustc.edu.cn/simple/
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p><strong>简单的<code>docker-compose.yml</code>示例讲解</strong></p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>version: <span class="token string">'3'</span>
services:
  db: 	<span class="token comment">#数据库服务</span>
    image: mysql:8.0	<span class="token comment">#使用的镜像</span>
    command:
      --default_authentication_plugin<span class="token operator">=</span>mysql_native_password
      --character-set-server<span class="token operator">=</span>utf8mb4
      --collation-server<span class="token operator">=</span>utf8mb4_unicode_ci
    volumes: 
      - db_data:/var/lib/mysql	<span class="token comment">#用数据卷名称，设置数据卷所挂载路径</span>
    restart: always
    environment: 
      MYSQL_ROOT_PASSWORD: root
      MYSQL_DATABASE: web-bug
  web-bug: <span class="token comment">#Web服务</span>
   depends_on:
    - db
   image: wintrysec/web-bug	<span class="token comment">#使用的镜像</span>
   ports:
    - <span class="token string">&quot;80:80&quot;</span>
   restart: always
   environment: 
    DB_HOST: db:3306
    DB_USER: root
    DB_PASSWORD: root
  volumes:	<span class="token comment">#如果上边挂载数据卷的路径为数据卷名称，必须在文件中配置数据卷</span>
   db_data:
    - <span class="token string">&quot;web-bug.sql&quot;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br></div></div><p><strong>注意事项：</strong></p> <p>YAML 语言基本语法规则如下</p> <blockquote><ul><li>大小写敏感</li> <li>使用缩进表示层级关系</li> <li>缩进时不允许使用Tab键，只允许使用空格。</li> <li>缩进的空格数目不重要，只要相同层级的元素左侧对齐即可</li> <li>每个散列项<strong>冒号</strong>和<strong>值</strong>之间至少有一个空格！</li></ul></blockquote> <p><a href="http://nodeca.github.io/js-yaml/" target="_blank" rel="noopener noreferrer">在线书写YAML(自动检测语法)<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></p> <h1 id="上传到docker-hub">上传到Docker Hub <a href="#上传到docker-hub" class="header-anchor">#</a></h1> <p><strong>1、注册<a href="https://hub.docker.com/repository/docker/wintrysec/wintrysec-lab" target="_blank" rel="noopener noreferrer">Docker Hub<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a>账户</strong></p> <p>2、使用Docker hub账号在验证<strong>本地登录</strong>  (如果用阿里云的私有仓库的话按阿里云帮助来)</p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>docker login
<span class="token comment">#登录信息信息,保存在~/.docker/config.json文件里</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><p><strong>3、注意事项</strong></p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>docker images
<span class="token comment">#查看本地镜像，如果 Docker ID/仓库名 不是属于你的账户是上传不了的</span>

<span class="token comment">#当然可以更改，命令如下</span>
docker tag 镜像ID 用户名称/Ubuntu:新的标签名<span class="token punctuation">(</span>tag<span class="token punctuation">)</span>

docker commit -a <span class="token string">'新镜像'</span> 容器ID 用户名称/镜像名:标签
<span class="token comment">#用这种方式，把使用这个ID的&quot;容器&quot;保存成型个新镜像</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br></div></div><p><strong>4、将镜像推送到远程仓库</strong></p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>docker push 用户名/仓库名:tagname
docker push wintrysec/wintrysec-lab:tagname
<span class="token comment">#这是Docker Hub官方仓库的命令，阿里云的私有仓库请看阿里云帮助</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div></div> <footer class="page-edit"><!----> <div class="last-updated"><span class="prefix">上次更新:</span> <span class="time">12/18/2021, 12:46:42 PM</span></div></footer> <div class="page-nav"><p class="inner"><span class="prev"><a href="/knowledge/base/git-base.html" class="prev"><i aria-label="icon: left" class="anticon anticon-left"><svg viewBox="64 64 896 896" focusable="false" data-icon="left" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M724 218.3V141c0-6.7-7.7-10.4-12.9-6.3L260.3 486.8a31.86 31.86 0 0 0 0 50.3l450.8 352.1c5.3 4.1 12.9.4 12.9-6.3v-77.3c0-4.9-2.3-9.6-6.1-12.6l-360-281 360-281.1c3.8-3 6.1-7.7 6.1-12.6z"></path></svg></i>
        Git基本用法
      </a></span> <span class="next"><a href="/knowledge/tools/nmap.html">
        nmap端口扫描
        <i aria-label="icon: right" class="anticon anticon-right"><svg viewBox="64 64 896 896" focusable="false" data-icon="right" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M765.7 486.8L314.9 134.7A7.97 7.97 0 0 0 302 141v77.3c0 4.9 2.3 9.6 6.1 12.6l360 281.1-360 281.1c-3.9 3-6.1 7.7-6.1 12.6V883c0 6.7 7.7 10.4 12.9 6.3l450.8-352.1a31.96 31.96 0 0 0 0-50.4z"></path></svg></i></a></span></p></div> </main> <!----></div><div class="global-ui"></div></div>
    <script src="/assets/js/app.f7464420.js" defer></script><script src="/assets/js/2.26207483.js" defer></script><script src="/assets/js/14.d2a5440c.js" defer></script>
  </body>
</html>